const enterpriseVue = new Vue({
    el: '#app',
    data() {
      return {
        pickerOptions: pickerOptions,
        rules: {
  
        },
        form:{
  
        },
        menuList: [],
        UserNumber: "",
        allCheckedKeys: [],
        loading: false
      }
    },
    mounted() {
      const System_SerialNumber = sessionStorage.getItem("System_SerialNumber")
      this.System_SerialNumber = System_SerialNumber
      this.getData()
      this.setCheckMenu(System_SerialNumber);
    },
    methods: {
      submitForm() {
        let _this = this
        _this.loading = true
        $.ajax({
          url: DomainName + '/SystemAuthorityEdit?token=' + $.cookie("token"),
          type: 'POST',
          data: {
            Data: JSON.stringify(_this.allCheckedKeys),
            System_SerialNumber: _this.System_SerialNumber,
          },
          success: function (res) {
            if (res.Status === 'success') {
              _this.$message.success("提交成功")
              window.history.go(-1)
            } else {
              _this.$message.error("提交失败，请稍后再试")
            }
          },
          error: function () {
            _this.$message.error("操作失败，请稍后再试")
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          }
        })
      },
      getData() {
        let _this = this
        $.ajax({
          type: 'GET',
          url: `${DomainName}/SystemMenu?token=${$.cookie('token')}&system=${JSON.parse($.cookie("system")).System_SerialNumber}`,
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          success: function (Result) {
            _this.menuList = Result      //将获取的数据存到表格数据中
          },
          dataType: "json"
        });
      },
      handleCheckChange() {
        let halfKeys = this.$refs.tree.getHalfCheckedKeys();
        let keys = this.$refs.tree.getCheckedKeys()
        this.allCheckedKeys = [...keys, ...halfKeys]
      },
      setCheckMenu(System_SerialNumber) {
        let _this = this
        $.ajax({
          type: 'POST',
          url: DomainName + "/querySystemAuthority?token=" + $.cookie("token"),
          data: {
            System_SerialNumber,
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          success: function (Result) {
            _this.handleCheckChange()
            _this.$refs.tree.setCheckedKeys(Result.Data, true)
          },
          dataType: "json"
        });
      },
    }
  })